//
//  QCEmotionPageView.swift
//  SwiftDemoWithSina
//
//  Created by qu on 2017/2/11.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit
private let pageViewCellId = "pageViewCellId"

class QCEmotionPageView: UICollectionView {

    
    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        
       let flowLayout = UICollectionViewFlowLayout()
        
        flowLayout.itemSize = CGSize(width: KSCREENW, height: 216-35)
        
        flowLayout.scrollDirection = .horizontal
        
        flowLayout.minimumLineSpacing = 0
        
        flowLayout.minimumInteritemSpacing = 0
        
        super.init(frame: frame, collectionViewLayout: flowLayout)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
//        backgroundColor = randomColor()
        dataSource = self
        
        register(QCEmotionPageViewCell.self, forCellWithReuseIdentifier: pageViewCellId)
        
    }

}

extension QCEmotionPageView:UICollectionViewDataSource {
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return QCEmotionTools.shared.allEmotions.count
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return QCEmotionTools.shared.allEmotions[section].count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: pageViewCellId, for: indexPath) as! QCEmotionPageViewCell
        cell.indexPath = indexPath
        
        cell.emotions = QCEmotionTools.shared.allEmotions[indexPath.section][indexPath.item]
        return cell
    }
}
